import numpy as np  #导入科学计算库numpy
import cv2 as cv  #导入opencv-python
#打开捕获器（0-系统默认摄像头）
j = 0
cap = cv.VideoCapture(0)
#打开失败
if not cap.isOpened():
    print("Cannot open camera")
    exit()
#打开成功
while True:
    #如果正确读取帧，ret为True
    ret, frame = cap.read()
    #读取失败，则退出循环
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break


    aim = cv.rectangle(frame, (200, 100), (450, 350), (0, 0, 255))

    cv.imshow('aim', aim)
    cv.resizeWindow("aim", 500, 400)
    key_pressed = cv.waitKey(60)
    #如果按下esc键，就退出循环
    if key_pressed == 27 or key_pressed == ord("q"):
        break
cap.release()  #释放捕获器
cv.destroyAllWindows() #关闭图像窗口
